package middlewares

import (
	"study_abroad_system_back_end/dao"
	"strconv"
	"github.com/gin-gonic/gin"
)

var site_total_visits int

func GetTotalVisits() int{
	return site_total_visits
}

func Counter() gin.HandlerFunc{
	return func(ctx *gin.Context) {
		redisdb := dao.GetRedis()
		redisdb.Incr(ctx, "site_total_visits")
		res, _ := redisdb.Get(ctx, "site_total_visits").Result()
		site_total_visits, _ = strconv.Atoi(res)
		ctx.Next()
	}
}